package com.ziyueyuwen.xiniao.service.baseservice.product.impl;

import com.ziyueyuwen.xiniao.bean.ZyProductStage;
import com.ziyueyuwen.xiniao.dao.ZyProductStageMapper;
import com.ziyueyuwen.xiniao.service.baseservice.product.ZyProductStageBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wancheng  on 2019/2/22.
 */
@Service
public class ZyProductStageBaseServiceImpl implements ZyProductStageBaseService {

    @Autowired
    ZyProductStageMapper zyProductStageMapper;

    @Override
    public ZyProductStage selectByPreKey(Integer id) {
        return zyProductStageMapper.selectByPrimaryKey(id);
    }

    @Override
    public ZyProductStage selectByZyProductStage(ZyProductStage param) {
        return zyProductStageMapper.selectOne(param);
    }

    @Override
    public List<ZyProductStage> selectListByZyProductStage(ZyProductStage param) {
        return zyProductStageMapper.select(param);
    }

    @Override
    public Boolean save(ZyProductStage stage) {
       int res = zyProductStageMapper.insertSelective(stage);
        return returnRes(res);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ZyProductStage saveUseGeneratedKeys(ZyProductStage stage) {
        zyProductStageMapper.insertUseGeneratedKeys(stage);
        return stage;
    }

    @Override
    public Boolean updateByPreKey(ZyProductStage stage) {
        int res = zyProductStageMapper.updateByPrimaryKeySelective(stage);
        return returnRes(res);
    }

    @Override
    public Boolean delete(Integer id) {
        ZyProductStage delete = selectByPreKey(id);
        delete.setIfDelete(true);
        return updateByPreKey(delete);
    }

    @Override
    public Boolean delete(ZyProductStage stage) {
        stage.setIfDelete(true);
        return updateByPreKey(stage);
    }

    @Override
    public Boolean deleteFromDisk(Integer id) {
        Integer res = zyProductStageMapper.deleteByPrimaryKey(id);
        return returnRes(res);
    }

    @Override
    public List<ZyProductStage> getUpperProductStage(Integer courseId) {
        return zyProductStageMapper.getUpperProductStage(courseId);
    }

}
